﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using QLTTAN.DTO;
namespace QLTTAN.DAL
{
    public class HocVienDAL
    {
        ConnectionData conn;

        public DataRow HocVien_GetInfo(HocVienDTO HV_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaHV";
            value[0] = HV_DTO.MaHV;

            return conn.GetData("HOCVIEN_GETINFO", name, value, Nparameter).Rows[0];
        }

        public DataTable HocVien_Load()
        {
            conn = new ConnectionData();
            return conn.GetData("HOCVIEN_LOAD");
        }

        
        public DataTable HocVien_LoadTiemNang()
        {
            conn = new ConnectionData();
            return conn.GetData("HOCVIEN_LOADHOCVIENTIEMNANG");
        }

        public DataTable HocVien_LoadTiemNang(LopHocDTO LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 3;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaLop";
            value[0] = LH_DTO.MaLop;

            return conn.GetData("HOCVIEN_LOADTIEMNANG_MaLop", name, value, Nparameter);
        }

        public DataTable HocVien_Find(HocVienDTO HV_DTO, LopHocDTO LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 5;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "TenHV";
            value[0] = HV_DTO.TenHV;
            name[1] = "GioiTinh";
            value[1] = HV_DTO.GioiTinh;
            name[2] = "DiaChi";
            value[2] = HV_DTO.DiaChi;
            name[3] = "TinhTrang";
            value[3] = HV_DTO.TinhTrang;
            name[4] = "MaLop";
            value[4] = LH_DTO.MaLop;

            return conn.GetData("HOCVIEN_FINDHOCVIEN", name, value, Nparameter);
        }

        public int HocVien_Insert(HocVienDTO HV_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 12;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "TenHV";
            value[0] = HV_DTO.TenHV;
            name[1] = "NgheNghiep";
            value[1] = HV_DTO.NgheNghiep;
            name[2] = "NgaySinh";
            value[2] = HV_DTO.NgaySinh;
            name[3] = "GioiTinh";
            value[3] = HV_DTO.GioiTinh;
            name[4] = "Email";
            value[4] = HV_DTO.Email;
            name[5] = "DiaChi";
            value[5] = HV_DTO.DiaChi;
            name[6] = "DienThoai";
            value[6] = HV_DTO.DienThoai;
            name[7] = "SoLuongLienLac";
            value[7] = HV_DTO.SoLuongLienLac;
            name[8] = "TrinhDoHienTai";
            value[8] = HV_DTO.TrinhDoHienTai;
            name[9] = "TrinhDoMuonHoc";
            value[9] = HV_DTO.TrinhDoMuonHoc;
            name[10] = "MaNgayRanh";
            value[10] = HV_DTO.MaNgayRanh;
            name[11] = "MaCaRanh";
            value[11] = HV_DTO.MaCaRanh;

            return conn.UpdateData("HOCVIEN_INSERT", name, value, Nparameter);
        }

        public int HocVien_Update(HocVienDTO HV_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 13;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaHV";
            value[0] = HV_DTO.MaHV;
            name[1] = "TenHV";
            value[1] = HV_DTO.TenHV;
            name[2] = "NgheNghiep";
            value[2] = HV_DTO.NgheNghiep;
            name[3] = "NgaySinh";
            value[3] = HV_DTO.NgaySinh;
            name[4] = "GioiTinh";
            value[4] = HV_DTO.GioiTinh;
            name[5] = "Email";
            value[5] = HV_DTO.Email;
            name[6] = "DiaChi";
            value[6] = HV_DTO.DiaChi;
            name[7] = "DienThoai";
            value[7] = HV_DTO.DienThoai;
            name[8] = "SoLuongLienLac";
            value[8] = HV_DTO.SoLuongLienLac;
            name[9] = "TrinhDoHienTai";
            value[9] = HV_DTO.TrinhDoHienTai;
            name[10] = "TrinhDoMuonHoc";
            value[10] = HV_DTO.TrinhDoMuonHoc;
            name[11] = "MaNgayRanh";
            value[11] = HV_DTO.MaNgayRanh;
            name[12] = "MaCaRanh";
            value[12] = HV_DTO.MaCaRanh;

            return conn.UpdateData("HOCVIEN_UPDATE", name, value, Nparameter);
        }

        public int HocVien_Delete(HocVienDTO HV_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaHV";
            value[0] = HV_DTO.MaHV;

            return conn.UpdateData("HOCVIEN_DELETE", name, value, Nparameter);
        }
    }
}
